package com.atguigu.gmall.common.config.minio.config;

import com.atguigu.gmall.common.config.minio.properties.MinioProperties;
import io.minio.MinioClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName: MinioConfiguration
 * @Author: WDD
 * @CreateTime: 2022-12-02  01:32
 * @Description:
 */
@Configuration //配置类
public class MinioConfiguration {
    //
    @Bean
    public MinioClient minioClient(MinioProperties minioProperties) throws Exception{
        //创建minioclient
        MinioClient client = new MinioClient(
                minioProperties.getEndpoint(),
                minioProperties.getAccessKey(),
                minioProperties.getSecretKey()
        );
        //判断桶是否存在
        boolean exists = client.bucketExists(minioProperties.getBucketName());
        if (!exists) {
            client.makeBucket(minioProperties.getBucketName());
        }
        return client;
    }
}
